package org.lql.chaos.mq.rabbitmq.controller;

import org.lql.chaos.mq.rabbitmq.producer.MultiExchangeMessageProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: liangqinglong
 * @date: 2025-08-08 13:53
 * @description: 多种交换机消息测试
 **/
@RestController
@RequestMapping("/multi-exchange")
public class MultiExchangeMessageController {

	@Autowired
	private MultiExchangeMessageProducer multiExchangeMessageProducer;

	@GetMapping("/send-fanout")
	public String sendFanout() {
		String msg = "Fanout消息";
		multiExchangeMessageProducer.sendFanoutMessage(msg);
		return "Fanout消息发送成功";
	}

	@GetMapping("/send-direct")
	public String sendDirect() {
		String msg = "Direct消息";
		multiExchangeMessageProducer.sendDirectMessage(msg);
		return "Direct消息发送成功";
	}

	@GetMapping("/send-topic-1")
	public String sendTopic() {
		// Queue1、Queue2 (匹配 *.rabbitmq.* 和 **.client)
		String msg = "com.rabbitmq.client";
		String routingKey = "com.rabbitmq.client";
		multiExchangeMessageProducer.sendTopicMessage(routingKey, msg);
		return "Topic消息发送成功";
	}

	@GetMapping("/send-topic-2")
	public String sendTopic2() {
		// Queue2 (匹配 com.#)
		String msg = "com.hidden.client";
		String routingKey = "com.hidden.client";
		multiExchangeMessageProducer.sendTopicMessage(routingKey, msg);
		return "Topic2消息发送成功";
	}

	@GetMapping("/send-topic-3")
	public String sendTopic3() {
		// Queue2 (匹配 com.#)
		String msg = "com.hidden.demo";
		String routingKey = "com.hidden.demo";
		multiExchangeMessageProducer.sendTopicMessage(routingKey, msg);
		return "Topic3消息发送成功";
	}

	@GetMapping("/send-topic-4")
	public String sendTopic4() {
		// Queue1 (匹配 *.rabbitmq.*)
		String msg = "java.rabbitmq.demo";
		String routingKey = "java.rabbitmq.demo";
		multiExchangeMessageProducer.sendTopicMessage(routingKey, msg);
		return "Topic4消息发送成功";
	}

	@GetMapping("/send-topic-5")
	public String sendTopic5() {
		// 不匹配任何队列（会被丢弃或返回生产者，需设置 mandatory）
		String msg = "java.util.concurrent";
		String routingKey = "java.util.concurrent";
		multiExchangeMessageProducer.sendTopicMessage(routingKey, msg);
		return "Topic5消息发送成功";
	}

	@GetMapping("/send-persistent")
	public String sendPersistent() {
		String msg = "Persistent消息";
		multiExchangeMessageProducer.sendPersistentMessage(msg);
		return "Persistent消息发送成功";
	}

	@GetMapping("/send-alternate")
	public String sendAlternate() {
		String msg = "Alternate消息";
		multiExchangeMessageProducer.sendAlternateMessage(msg);
		return "Alternate消息发送成功";
	}
}
